import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/health/title_view.dart';
import 'package:flutter_eve_plugin/constants/constant.dart';
import 'package:flutter_eve_plugin/model/health/sys_health_property.dart';
import 'package:flutter_eve_plugin/plugin/main.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/store_vm/health/main.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

import 'package:flutter_eve_plugin/utils/image_util.dart';

class RecommendDrugWidget extends StatelessWidget {
  final PropertyHealthDataInfo info;

  const RecommendDrugWidget({Key key, this.info}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(converter: (store) {
      return AppStateViewModel(
          state: store.state,
          healthStateViewModel: HealthStateViewModel(pushMallPage: () {
            final param = {'sub_type': this.info.healthSystem};
            PluginEve.sendMessage(PluginConstant.httpAllGoodsType,
                param: param, httpType: HttpType.POST);
          }));
    }, builder: (context, vm) {
      if (info.drugName == null || info.drugName.isEmpty) {
        return Container();
      }
      return Container(
        margin: EdgeInsets.only(
            left: setRatio(15),
            right: setRatio(15),
            top: setRatio(27),
            bottom: setRatio(10)),
        width: setRatio(345),
        decoration: BoxDecoration(
          image: DecorationImage(
              image: AssetImage(imageUtilHuPo('health/icon_dotted_border@2x')),
              fit: BoxFit.fill),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            SizedBox(
              height: setRatio(25),
            ),
            HealthTitleViewWidget(
              title: '治疗药物',
            ),
            SizedBox(
              height: setRatio(15),
            ),
            Container(
              height: setRatio(50),
              margin: EdgeInsets.only(left: setRatio(20), bottom: setRatio(26)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Container(
                      width: setRatio(50),
                      decoration: BoxDecoration(
                          border: Border.all(
                              color: Color(0xFF7975FF), width: setRatio(1)),
                          borderRadius:
                              BorderRadius.all(Radius.circular(setRatio(4)))),
                      child: Image(
                        image: NetworkImage(info.drugIcon),
                      )),
                  SizedBox(
                    width: setRatio(15),
                  ),
                  Column(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(
                        info.drugName,
                        style: TextStyle(
                            color: Color(0xFF7975FF), fontSize: setTextSp(14)),
                      ),
                      Text.rich(TextSpan(
                          text: '疾病值',
                          style: TextStyle(
                              color: Color(0xFF999999),
                              fontSize: setTextSp(11)),
                          children: [
                            TextSpan(
                                text: '${info.effectValue}',
                                style: TextStyle(
                                    color: Color(0xFF7975FF),
                                    fontSize: setTextSp(11)))
                          ]))
                    ],
                  ),
                  Expanded(child: Container()),
                  SizedBox(
                    width: setRatio(95),
                    height: setRatio(26),
                    child: RaisedButton(
                      onPressed: vm.healthStateViewModel.pushMallPage,
                      shape: StadiumBorder(),
                      color: Color(0xff8159f5),
                      child: Text(
                        '前往商城',
                        style: TextStyle(
                            color: Colors.white, fontSize: setTextSp(14)),
                      ),
                    ),
                  ),
                  SizedBox(
                    width: setRatio(15),
                  )
                ],
              ),
            )
          ],
        ),
      );
    });
  }
}
